<template>
  <bfs-asn-list-std ref="asnListRef">
    <template v-slot:dropdownSlot="props">
      <q-btn-dropdown color="primary" icon="view_list" label="IMS接口反填" :disable="props.data.selectedItem.length===0">
        <q-list dense>
          <q-item clickable v-close-popup @click="createDecBack(props.data.selectedItem)">
            <q-item-section avatar>
              <q-icon name="fiber_manual_record"></q-icon>
            </q-item-section>
            <q-item-section>
              <q-item-label>报关发票反填</q-item-label>
            </q-item-section>
          </q-item>
          <q-item clickable v-close-popup @click="createBondedTransferBackFill(props.data.selectedItem)">
            <q-item-section avatar>
              <q-icon name="fiber_manual_record"></q-icon>
            </q-item-section>
            <q-item-section>
              <q-item-label>保税转仓反填</q-item-label>
            </q-item-section>
          </q-item>
        </q-list>
      </q-btn-dropdown>
    </template>
  </bfs-asn-list-std>
</template>

<script lang="ts">
export default {
  name: 'AsnList'
}
</script>

<script lang="ts" setup>
import {BfsAsnInfo} from '@njt/bfs/defs/work/asn'
import _ from 'lodash'
import {ref} from 'vue'

let asnListRef = ref<any>()
const createDecBack = function (list: BfsAsnInfo[]) {
  void $f.ui.messageBox({
    caption: '操作确认',
    text: '确定要创建报关发票反填吗',
    icon: 'Question',
    buttons: 'OkCancel',
    delayClose: true,
  }).then((btn) => {
    if (btn === 'ok') {
      $f.axios
        .post('/project/mhlbc/work/asn/asn-create-dec-back-fill',_.map(list, 'asnId'))
        .then(() => {
          $f.ui.showNotifySucceeded('创建成功')
          $f.ui.closeMsgBox()
          asnListRef.value.loadListData(2)
        })
        .catch((err) => {
          $f.ui.closeMsgBox()
          if (err.response?.data?.errorList?.length) {
            $f.ui.showErrorListDlg(err.response.data)
          } else {
            $f.ui.showNotifyFailed($f.getAxiosErrMsg(err))
          }
        })
    }
  })

}

const createBondedTransferBackFill = function (list: BfsAsnInfo[]) {
  void $f.ui.messageBox({
    caption: '操作确认',
    text: '确定要创建保税转仓反填吗',
    icon: 'Question',
    buttons: 'OkCancel',
    delayClose: true,
  }).then((btn) => {
    if (btn === 'ok') {
      $f.axios
        .post('/project/mhlbc/work/asn/bonded-transfer-back-fill',_.map(list, 'asnId'))
        .then(() => {
          $f.ui.showNotifySucceeded('创建成功')
          $f.ui.closeMsgBox()
          asnListRef.value.loadListData(2)
        })
        .catch((err) => {
          $f.ui.closeMsgBox()
          if (err.response?.data?.errorList?.length) {
            $f.ui.showErrorListDlg(err.response.data)
          } else {
            $f.ui.showNotifyFailed($f.getAxiosErrMsg(err))
          }
        })
    }
  })

}

</script>

<style scoped>

</style>